﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DXApplicationTangche.report;
using DevExpress.XtraReports.UI;
using DXApplicationTangche.service;
using DXApplicationTangche.DTO;
using mendian;
using DevExpress.XtraGrid.Demos.util;

namespace DXApplicationTangche.UC.订单一览新.销售确认单
{
    public partial class Form销售日记账预览 : DevExpress.XtraEditors.XtraForm
    {
        private Model销售日记账预览 model;
        public Form销售日记账预览(String dateTimeStart,String dateTimeEnd)
        {
            InitializeComponent();
            this.model = new Model销售日记账预览(dateTimeStart,dateTimeEnd);
            this.gridControl销售日记账.DataSource = this.model.saleConfirmExportDTOs;
            this.advBandedGridView定制订单.RefreshData();
        }

        private void simpleButton预览_Click(object sender, EventArgs e)
        {
            XtraReport销售日记账预览 reportd定制 = new XtraReport销售日记账预览(this.model.VO导出定制s);
            ReportPrintTool tool定制 = new ReportPrintTool(reportd定制);
            tool定制.ShowPreviewDialog();
            XtraReport销售日记账预览 report客套 = new XtraReport销售日记账预览(this.model.VO导出客套s);
            ReportPrintTool tool客套 = new ReportPrintTool(report客套);
            tool客套.ShowPreviewDialog();
        }
    }

    public class VOSaleConfirmExport
    {
        public String id { get; set; }    //
        public String quoteId { get; set; }    //  应用分录id
        public String mobile { get; set; }    //   客户电话
        public String customerName { get; set; }   //客户姓名
        public String orderDate { get; set; }    //  日期
        public String businessType { get; set; }    // 业务类型    SalesTypeConsts
        public String barcode { get; set; }    //  成衣码
        public String refBarcode { get; set; }    //   参考成衣码
        public String styleNameCn { get; set; }    //  款式
        public String materialCode { get; set; }    // 面料
        public Image materialImage { get; set; }    // 面料
        public String materialNameCn { get; set; }  //面料名称
        public String styleSizeCd { get; set; }    //  尺码
        public Double price { get; set; }    //    金额
        public int quantity { get; set; }    //    数量
        public String store { get; set; }    //    销售组织
        public String storeName { get; set; }    //    销售组织name
        public String assistant { get; set; }    //    负责人
        public String assistantName { get; set; }    //    负责人name
        public String remarks { get; set; }    //  备注
        public Boolean synchronize { get; set; }    //  是否同步销售订单
        public Boolean deprecated { get; set; } //  是否作废
        public String saleOrderDetailId { get; set; }  //  销售分录ID
        public String manufactureOrderId { get; set; }  //  生产订单id
        public Double adjustPrice { get; set; } //  调整价格
        public Double designPrice { get; set; } //  设计费用
        public List<SaleConfirmQueryDetailDTO> saleConfirmQueryDetailDTOList { get; set; } = new List<SaleConfirmQueryDetailDTO>();
        //  样衣信息
        public String saleStyleId { get; set; } //  销售款式id  top.toptimus.style.dao.SaleStyleDao.id
        public String saleStyleCode { get; set; }   //  款号，销售定义 top.toptimus.style.dao.SaleStyleDao.saleStyleCode
        public String sampleImagePath { get; set; } //  样衣图片
        public Image sampleImage { get; set; } //  样衣图片
        public Double salePrice { get; set; }   //  零售价
        //  样衣款式信息
        public String styleTag { get; set; }    //  款式描述
        public String styleSexFlag { get; set; }   //  男 女 男童 女童
        public String styleCategoryId { get; set; } //  款式类别ID
        public String styleCategoryCode { get; set; }   //  款式类别编码
        public String styleCategoryName { get; set; }   //  款式类别名称
        public Double finalPrice { get; set; }   //  最后金额
        public VOSaleConfirmExport()
        {

        }

        public VOSaleConfirmExport(SaleConfirmExportDTO saleConfirmExportDTO)
        {
            this.id = saleConfirmExportDTO.id;
            this.quoteId = saleConfirmExportDTO.quoteId;
            this.mobile = saleConfirmExportDTO.mobile;
            this.customerName = saleConfirmExportDTO.customerName;
            this.orderDate = saleConfirmExportDTO.orderDate.ToString("yyyy-MM-dd");
            this.businessType = saleConfirmExportDTO.businessType;
            this.barcode = saleConfirmExportDTO.barcode;
            this.refBarcode = saleConfirmExportDTO.refBarcode;
            this.styleNameCn = saleConfirmExportDTO.styleNameCn;
            this.materialCode = saleConfirmExportDTO.materialCode;
            this.materialNameCn = saleConfirmExportDTO.materialNameCn;
            if (!String.IsNullOrEmpty(saleConfirmExportDTO.styleSizeCd))
            {
                try { this.styleSizeCd = saleConfirmExportDTO.styleSizeCd.Replace("IGS_GROUP_SIZE-", "").Replace("EGS_GROUP_SIZE-", ""); } catch { }
            }
            this.price = saleConfirmExportDTO.price;
            this.quantity = saleConfirmExportDTO.quantity;
            this.store = saleConfirmExportDTO.store;
            this.storeName = saleConfirmExportDTO.storeName;
            this.assistant = saleConfirmExportDTO.assistant;
            this.assistantName = saleConfirmExportDTO.assistantName;
            this.remarks = saleConfirmExportDTO.remarks;
            this.synchronize = saleConfirmExportDTO.synchronize;
            this.deprecated = saleConfirmExportDTO.deprecated;
            this.saleOrderDetailId = saleConfirmExportDTO.saleOrderDetailId;
            this.manufactureOrderId = saleConfirmExportDTO.manufactureOrderId;
            this.adjustPrice = saleConfirmExportDTO.adjustPrice;
            this.designPrice = saleConfirmExportDTO.designPrice;
            this.saleConfirmQueryDetailDTOList = saleConfirmExportDTO.saleConfirmQueryDetailDTOList;
            this.saleStyleId = saleConfirmExportDTO.saleStyleId;
            this.saleStyleCode = saleConfirmExportDTO.saleStyleCode;
            this.sampleImagePath = saleConfirmExportDTO.sampleImagePath;
            this.salePrice = saleConfirmExportDTO.salePrice;
            this.styleTag = saleConfirmExportDTO.styleTag;
            this.styleSexFlag = saleConfirmExportDTO.styleSexFlag;
            this.styleCategoryId = saleConfirmExportDTO.styleCategoryId;
            this.styleCategoryCode = saleConfirmExportDTO.styleCategoryCode;
            this.styleCategoryName = saleConfirmExportDTO.styleCategoryName;
            this.finalPrice = saleConfirmExportDTO.price * saleConfirmExportDTO.quantity + saleConfirmExportDTO.adjustPrice + saleConfirmExportDTO.designPrice;
            try
            {
                this.materialImage =
                    FileService.GetImageByUrl(
                        URL.图片url + URL.面料图片路径 +
                        RestCall.httpGetMethod(URL.接口url + "/image/getImagePath?materialCode=" + saleConfirmExportDTO.materialCode)
                        );
            }
            catch
            {
                this.materialImage = FunctionHelper.getSSHIRT();
            }
            try
            {
                this.sampleImage = FileService.GetImageByUrl(URL.图片url + URL.销售样衣实例图片路径 + saleConfirmExportDTO.sampleImagePath);
            }
            catch
            {
                this.sampleImage = FunctionHelper.getSSHIRT();
            }
        }
    }
    
    public class Model销售日记账预览
    {
        public List<SaleConfirmExportDTO> saleConfirmExportDTOs { get; set; } = new List<SaleConfirmExportDTO>();
        public List<VOSaleConfirmExport> VO导出定制s { get; set; } = new List<VOSaleConfirmExport>();
        public List<VOSaleConfirmExport> VO导出客套s { get; set; } = new List<VOSaleConfirmExport>();
        public Model销售日记账预览(String dateTimeStart, String dateTimeEnd)
        {
            this.saleConfirmExportDTOs = 销售确认Service.getSaleConfirmExportListByDateTimeStr(dateTimeStart, dateTimeEnd);
            foreach (SaleConfirmExportDTO item in this.saleConfirmExportDTOs)
            {
                if ("定制下单".Equals(item.businessType))
                {
                    this.VO导出定制s.Add(new VOSaleConfirmExport(item));
                }
                else
                {
                    this.VO导出客套s.Add(new VOSaleConfirmExport(item));
                }
            }
        }
    }
}